package com.ccq.service;

import com.alibaba.fastjson.JSON;
import com.ccq.mapper.RecordMapper;
import com.ccq.model.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LastRecordServicce {
    @Autowired
    RecordMapper recordMapper;

    public String rentlist(Integer page){
        page=(page-1)*5;
        List<Record> ls=recordMapper.selectPage(page);
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

    public String add(Record record){
        int add=recordMapper.insertSelective(record);
        List<Record> ls=recordMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String eidts(int id){
        Record se=recordMapper.selectByPrimaryKey(id);
        String aListJson = JSON.toJSONString(se);
        return aListJson;
    }

    public String edit(Record renting){
        int  se=recordMapper.updateByPrimaryKey(renting);
        List<Record> ls=recordMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String del(int id){
        int del=recordMapper.deleteByPrimaryKey(id);
        List<Record> ls=recordMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        System.out.println("删除成功！");
        return aListJson;
    }
}
